home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / OTFLIP.ZIP / pageflip.pas < prev   
Pascal/Delphi Source File  |  1996-02-23  |  5KB  |  118 lines

  1. { Shows how a virtual screen works
  2.   By Vulture / Outlaw Triad }
  3.  
  4. {$X+}
  5.  
  6. Program Virtuality;                       { Virtual screen program }
  7.  
  8. Uses Crt;                                 { Used units }
  9.  
  10. Type Virtual  = Array [1..64000] of byte; { The size of our Virtual Screen }
  11.      VirPoint = ^Virtual;                 { Pointer to the virtual screen }
  12.  
  13. Const VGA = $A000;                        { VGA Segment }
  14.  
  15. Var Virscr: VirPoint;                     { The actual virtual screen }
  16.     Vaddr : Word;                         { Segment of our virtual screen }
  17.  
  18. Procedure VideoMode(Mode: Byte); Assembler;  { Used to switch to gfxmode }
  19. Asm
  20.   mov  ah,00
  21.   mov  al,Mode
  22.   int  10h
  23. End;
  24.  
  25. Procedure SetMemory;                      { Allocates memory }
  26. Begin
  27.   GetMem(VirScr,64000);
  28.   Vaddr := Seg(Virscr^);
  29. End;
  30.  
  31. Procedure FreeMemory;                     { Frees the memory }
  32. Begin
  33.   FreeMem(VirScr,64000);
  34. End;
  35.  
  36. Procedure SetPixel(X,Y:Integer;Color:Byte;Where:Word); Assembler;
  37. Asm                         { TP automatically pushes and pops ES }
  38.   mov  ax,[Where]           { Move destination in AX }
  39.   mov  es,ax                { es => points to VGA or virtual screen }
  40.   mov  di,Y                 { Move Y into DI }
  41.   mov  ax,Y                 { Move Y into AX }
  42.   shl  di,8                 { DI := DI * 256 }
  43.   shl  ax,6                 { AX := AX * 64 }
  44.   add  di,ax                { DI := Y * 320 }
  45.   mov  ax,X                 { Move X into AX }
  46.   add  di,ax                { DI = X + (Y*320)   final location }
  47.   mov  al,Color             { Set color }
  48.   mov  byte ptr es:[di],al  { Place the dot }
  49. End;
  50.  
  51. Procedure ClearScreen(Color:Byte;Where:Word); Assembler;
  52. Asm
  53.   mov  ax,Where             { Move destination in AX }
  54.   mov  es,ax                { ES points to VGA or virtual screen }
  55.   xor  di,di                { Start at begin of screen }
  56.   cld                       { Clear direction flag }
  57.   mov  al,Color             { Set color in AL }
  58.   mov  ah,al                { And in ah }
  59.   mov  cx,320*50            { Do the entire screen (using dwords!) }
  60.   db   $66                  { We want to use dwords }
  61.   rep  stosw                { Store the word in ax to es:[di] }
  62. End;
  63.  
  64. Procedure FlipPage(source,dest:Word); Assembler; { Pretty fast! }
  65. Asm
  66.   push    ds                { Put DS on stack }
  67.   mov     ax,[Dest]
  68.   mov     es,ax             { es points to destination segment }
  69.   mov     ax,[Source]
  70.   mov     ds,ax             { ds points to source segment }
  71.   xor     si,si             { Start at begin of source }
  72.   xor     di,di             { Start at begin of destination }
  73.   mov     cx,16000          { Screen size = 64 kbytes. Use dwords: needed 16000 }
  74.   db      $66               { Use extended registers for speed (e.g eax) }
  75.   rep     movsw             { Copy ds:si to es:di }
  76.   pop     ds                { Recall DS from stack }
  77. End;
  78.  
  79. Procedure PlotDots;
  80. Var Loop1: Integer;
  81. Begin
  82.   For Loop1 := 1 to 5000 Do
  83.     SetPixel(Random(320),Random(200),Random(256),Vaddr);
  84. End;
  85.  
  86. Begin
  87.   ClrScr;
  88.   Writeln('In this program I will setup a virtual screen and fill it with');
  89.   Writeln('random pixels. At first you won''t see anything on the screen.');
  90.   Writeln('After a keypress the data is flipped to the VGA screen.');
  91.   Writeln;
  92.   Write('Press any key...');
  93.   Readkey;
  94.   RandoMize;                { Truly random }
  95.   SetMemory;                { Get memory }
  96.   ClearScreen(0,Vaddr);     { Clear the memory }
  97.   VideoMode($13);           { Get in gfxmode 13h 320*200*256 }
  98.   PlotDots;                 { Plot random dots on the virtual screen }
  99.   Readkey;                  { Wait for a key }
  100.   FlipPage(Vaddr,VGA);      { Flip it to the VGA }
  101.   Readkey;                  { Wait for a key }
  102.   VideoMode($3);            { And back to textmode }
  103.   FreeMemory;               { Free memory }
  104.   Writeln('▄  ▄▄  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  ▄▄  ▄');
  105.   Writeln('                    - An Outlaw Triad Production (c) 1996 -');
  106.   Writeln;
  107.   Writeln('                             Code∙∙∙∙∙∙∙∙∙∙Vulture');
  108.   Writeln;
  109.   Writeln('                            -=≡ Outlaw Triad Is ≡=-');
  110.   Writeln;
  111.   Writeln('         Vulture(code) ■ Dazl(artist) ■ Troop(sysop) ■ Xplorer(artist)');
  112.   Writeln('▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄');
  113. End.
  114.  
  115.  
  116.  
  117.  
  118. { Thanx must go to Denthor / Asphyxia for teaching me some usefull stuff }